package com.ym.excel.controller;

import com.ym.excel.model.ExcelModel;
import com.ym.excel.mq.name.MqState;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(name = "/test")
public class TestController {

    private final RabbitTemplate rabbitTemplate;

    @Autowired
    public TestController(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    @RequestMapping(name = "/export")
    public void testExport(HttpServletResponse response) throws Exception {
        Map<String, Object> map = new HashMap<>();
        List<List<ExcelModel>> lists = data();
        String personId = "1111";
        map.put("lists", lists);
        map.put("personId", personId);
        rabbitTemplate.convertAndSend(MqState.service_form_export, map);
    }

    //伪造数据
    private List<List<ExcelModel>> data() {
        List<List<ExcelModel>> models = new ArrayList<>();
        for (int j = 0; j < 3; j++) {
            List<ExcelModel> list = new ArrayList<ExcelModel>();
            for (int i = 0; i < 10; i++) {
                ExcelModel data = new ExcelModel();
                data.setNum(i + "");
                data.setServiceProcessNumber(i * 1000 + "");
                data.setServiceFlowProcessStatus("正常");
                data.setFlowNodeName("支付节点");
                data.setCurrentPersonName("管理员");
                data.setStopContent("无");
                list.add(data);
            }
            models.add(list);
        }
        return models;
    }
}
